javascript error : periodLookup[periodStr] is undefined, why is it throwing this error?
Posted
by Mo
on Stack Overflow
See other posts from Stack Overflow
or by Mo
Published on 2010-06-11T12:47:17Z
Indexed on
2010/06/11
12:53 UTC
Read the original article
Hit count: 140
JavaScript
|html
Hi
i have this method:
set_period_help_text: function(periodInput){
var metric = MonitorMetric.getSelectedMetric();
var periodStr = $('select[name=metric_period]').val();
var datapoints = Number(periodInput.attr("value"));
var period = datapoints * periodLookup[periodStr][0];
}
var periodLookup = {
"OneMinute": [1, "minute"],
"FiveMinute": [5, "minute"],
"OneHour": [1, "hour"],
"OneDay": [1, "day"],
"OneWeek": [1, "week"]
};
where var periodStr is being retrived from a dropdown menue that only has the values:
"OneMinute"
"FiveMinute"
"OneHour"
"OneDay"
"OneWeek"
i get a java script error when the page loads:
periodLookup[periodStr] is undefined [Break on this error] var period = datapoints * periodLookup[periodStr][0];
© Stack Overflow or respective owner